home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / tbones07.zip / TSRKEY.ASM < prev    next >
Assembly Source File  |  1991-01-20  |  16KB  |  369 lines

  1. ;***************************
  2. PAGE    55,132          ;Format .LST listing at 55 lines by 132 columns.
  3. TITLE   TSRKEY Version 0.4 Jan 20 1991 Robert Curtis Davis
  4. SUBTTL  Introduction
  5. ;******************************************************************************
  6. ;
  7. ;       TSRKEY.ASM      Version 0.4     Jan 20 91
  8. ;       A part of the TBONES software package.
  9. ;
  10. ;       Copyright (C) 1990, 1991 by Robert Curtis Davis,
  11. ;    All Rights Reserved.
  12. ;
  13. ;    DESCRIPTION:
  14. ;    ASM Program template for Terminate-and-Stay-Resident (TSR) programs
  15. ;        that are activated by a specified HotKey..
  16. ;
  17. ;    PURPOSE:
  18. ;       Provides a skeletal framework program useful as a starting point
  19. ;       in the design of your own HotKey TSRs.
  20. ;
  21. ;                   E-mail address:
  22. ;              Internet: sonny@trantor.harris-atd.com
  23. ;
  24. ;                          US Mail:
  25. ;                                   430 Bahama Drive
  26. ;                                   Indialantic, FL 32903
  27. ;
  28. ;***************************************************************************
  29. ;
  30. ; Special thanks to David Kirschbaum, whose Toad Hall Tweaks significantly
  31. ; improved TBONES' code:
  32. ;
  33. ;v0.11    Toad Hall Tweak, 25 Nov 90
  34. ; - Idiosyncracy: I like my constant labels all-upper-case
  35. ;   and my variable labels lower-case.
  36. ; - Load AX with words, not byte-by-byte
  37. ; - Load ES directly with environ seg, no need to pass thru AX.
  38. ; - Save ES directly to variable, no need to pass thru AX.
  39. ; - Let compiler do basic arithmetic (figuring paras of memory to save).
  40. ; - Use processes just to be neat.  (That FAR NewInt09 is important!)
  41. ; - INS is a reserved word for TASM v1.0. Changed to INSRT.
  42. ;**************************************************************************
  43. SUBTTL  Code Segment (Resident)
  44. PAGE
  45. ;**************************************************************************
  46. ;
  47. CodeSeg        segment
  48.                 assume  cs:CodeSeg,ds:CodeSeg
  49. BeginDump       EQU     $       ;This, from Roy Silvernail, makes
  50.                                 ;TASM v.1.0 happy below.
  51. ;
  52.         org    2CH        ;0.11
  53. envseg        label    word        ;0.11
  54. ;
  55.         org    100h        ;ORG for all COM programs.
  56. ;
  57. Entry           PROC    NEAR            ;v0.11
  58.         jmp    TSRinit        ;Jump over resident portion and
  59.                     ;initialize things and make code
  60.                     ;between Entry: and TSRinit: resident.
  61. ;  
  62. ; Old Keyboard Interrupt Vector (Int 09h handler address) is stored 
  63. ; here during TSR initialization:
  64. oldint09        dd      ?
  65. ;
  66. Entry           ENDP                    ;v0.11
  67.  
  68. ; For this HotKey TSR Template, specify Keyboard Interrupt 09h as the Hook:
  69. HOOK09            equ     09h   ;Hooked Interrupt number.
  70. ;
  71. bellgate    db    0    ;Gate closed (=1) when in Bell routine.
  72.                 ;Gate open (=0) when not in Bell routine.
  73. ;
  74. ; EQUs defining Key Flag weights in the Key Flag Byte:
  75. RSHIFT        equ    00000001B        ;Right Shift Key Flag weight.
  76. LSHIFT        equ    00000010B        ;Left Shift  Key Flag weight.
  77. CTRL        equ    00000100B        ;Ctrl        Key Flag weight.
  78. ALT        equ    00001000B        ;Alt         Key Flag weight.
  79. ;SCROLL          equ     00010000B               ;Scroll Lock Key Flag weight.
  80. ;NUM             equ     00100000B               ;Num Lock    Key Flag weight.
  81. ;CAPS            equ     01000000B               ;Caps Lock   Key Flag weight.
  82. INSRT        equ    10000000B        ;Ins         Key Flag weight.
  83. ;*************************************************************************
  84. ;       Mask to mask out Num, Caps, and Scroll Lock bits from key flag byte.
  85. LockKeyMask     EQU     10001111B
  86. ;
  87. ;       Your HotKey is specified here:
  88. ;       (This sample HotKey is set for Ctrl-Alt-K)
  89. ;
  90. ; Specify TSR's HotKey Shift Keys:
  91. KEYFLAGBYTE    equ    CTRL+ALT        ;HotKey Flags
  92. ;
  93. ; Specify TSR's HotKey Scan Code:
  94. HOTKEY          equ     25h                     ;'K' key.
  95. ;
  96. ;*************************************************************************
  97. SUBTTL User-supplied TSR Routine
  98. PAGE
  99. ;*************************************************************************
  100. ROUTINE         PROC    NEAR
  101. ;*************************************************************************
  102. ;    Code for your HotKey-triggered TSR routine  GOES HERE:
  103. ;    ( Here, a dummy routine has been placed which simply rings the
  104. ;      terminal Bell whenever the TSR is triggered. )
  105. ;
  106. ;    Announce this dummy TSR's trigger by a Bell signal:
  107. ;
  108. Enter:
  109.                 mov     al,07h          ;al = ASCII Bell.
  110.                 mov     bh,0            ;Video page.
  111.                 mov     cx,1            ;No. of bytes to write.
  112.                 mov     ah,0Eh          ;BIOS Int10,OEh=TTY Screen.
  113.                 Int     10h             ;Write ASCII Bell to screen.
  114. ;
  115. Exit:
  116.                 ret                     ;Return from TSR routine.
  117. ;
  118. ROUTINE         endp
  119. ;
  120. ;    End of your HotKeyed TSR routine.
  121. ;***************************************************************************
  122. SUBTTL Hooked Interrupts
  123. PAGE
  124. ;***************************************************************************
  125. ;
  126. NewInt09    PROC    FAR        ;v0.01
  127. ;
  128. ; The following three instructions often are said to "simulate an interrupt"
  129. ; that calls the PRIOR interrupt handler routine and then the prior interrupt
  130. ; handler's IRET instruction pops the flags and returns here to the point
  131. ; after the following CALL instruction.
  132. ;    The reason for "simulating the interrupt" here is to give prior (and
  133. ; presumably more time-critical) handlers a shot at processing this interrupt
  134. ; before we process with this TSR's code.
  135. ;
  136.         pushf            ;Push flags as a true interrupt would.
  137.                 cli                     ;Be sure interrupts are disabled.
  138.         call    CS:oldint09    ;Call FAR PTR address of old interrupt
  139. ;                    ;     handler routine.
  140. ;
  141. ;
  142.                 push    ax      ;Prepare to check for Hotkey.
  143.                 push    bx      ;Save all registers (DS is already pushed).
  144.                 push    cx
  145.                 push    dx
  146.                 push    si
  147.                 push    di
  148.                 push    bp
  149.                 push    ds
  150.                 push    es
  151. ;
  152.                 push    CS              ;Set up data segment
  153.                 pop     DS              ;register to point to code segment.
  154. ;
  155.                 ASSUME  DS:CodeSeg      ;v0.01
  156. ;
  157. ;       Determine if the current Keyboard Interrupt (Int09h) occurred
  158. ;       because this TSR's HotKey was pressed:
  159.                 in      al,60h          ;Get current Key Scan Code.
  160.                 cmp     al,HOTKEY       ;Is it HotKey's Scan Code?
  161.                 jne     Exit09          ;Exit if not.
  162.                 mov     ah,02h          ;Int16h,Fcn02h:GetKEYFLAGBYTE.
  163.                 Int     16h             ;Return Key Flag Byte in al.
  164.                 and     al,LockKeyMask  ;Mask out Num, Caps, Scroll Lock bits.
  165.                 cmp     al,KEYFLAGBYTE  ;Are the HotKey Flags active ?
  166.                 jne     Exit09          ;Exit if not.
  167. ;
  168. ;       At this point, Hotkey is known to have been pressed. First, purge
  169. ;       the DOS Keyboard type-ahead buffer of the hot key(s) so they won't
  170. ;       be passed on to DOS:
  171. ;
  172. ClrKbdBuf:      ;Clear Keyboard buffer:
  173.                 mov     ah,01h          ;Get Keyboard buffer status
  174.                 int     16h             ;via BIOS Interrupt 16h.
  175.                 jz      BufClr          ;Jump if buffer empty.
  176.                 mov     ah,00h          ;Get key from buffer (to purge it)
  177.                 int     16h             ;via BIOS Interrupt 16h.
  178.                 jmp     ClrKbdBuf       ;Loop back to purge another key.
  179. BufClr:
  180. ;
  181. ; We shall allow other interrupts to occur during our TSR ROUTINE.
  182. ; If we didn't allow other interrupts (through the STI instruction),
  183. ; we could lock out time-critical interrupts from access to the CPU during
  184. ; our TSR routine. However, by allowing interrupts during our routine, we 
  185. ; have an increased responsibility to make sure critical portions of our
  186. ; own code is not re-entered. (The "bellgate" stuff below is an example
  187. ; of a measure necessary to keep us from re-entering our own TSR's code).
  188. ; What we really want to do by allowing interrupts is to make the CPU avail-
  189. ; able to OTHER critical interrupt service routines WITHO